package test;
import java.io.*;

import org.junit.Test;
import icode.*;
import util.*;

import static org.junit.Assert.*;

import org.junit.Test;

import parser.MiniP;
import parser.Start;

public class ICodeGen extends TestCaseOutput {
	private final static String DATA = "data/";
    private final static String RESULT = "result/";
    private final static String FILE_EXTENSION = ".calc";
    private final static String RESULT_EXTENSION = ".res";
    
    private void assertCorrectOutput(String testName) {
        String fullName = testName + FILE_EXTENSION;
        generate(DATA + fullName);
        assertOutput(new File(RESULT + fullName + RESULT_EXTENSION));
    }
	
    @Test
	public void test() {
		assertCorrectOutput("test");
	}
    
    private static void generate(String arg) {
        try {
            MiniP parser = new MiniP(new FileReader(arg));
            Start start = parser.start();
            start.analyze();
            start.numbering();
            start.icodeGen();
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

}
